﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class but_ajax_SanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request.QueryString["type"];
        string _id = Request.QueryString["id"];// de lay thong tin 1 san pham
        type = TTQT.TTQT_Code.TTQTCommon.isNull(type, "");
        Response.ContentType = "application/json";
        if(string.IsNullOrEmpty(type))
        {
            Response.Write("");
        }
        //Lay toan bo san pham
        if(type.Equals("getall"))
        {
            Response.Write(new SanPhamDAO().sanPHam_GetByNhomId_Json("-1", "-1"));
        }
        //Lay theo nhom
        if (type.Equals("sp"))
        {
            string catid = Request.QueryString["catid"];
            string result = new SanPhamDAO().sanPHam_GetByNhomId_Json(catid, "-1");
            Response.Write(result);
        }
        //Lay top soluong san pham cung nhom can cu theo id truyen vao cua 1 san pham
        if(type.Equals("spcungnhom"))
        {
            string id = Request.QueryString["id"];
            string soluong = Request.QueryString["soluong"];
            Response.Write(new SanPhamDAO().sanPHam_GetTopCungNhom_Json(id, soluong));
        }
        //Lay cac san pham hot
        if (type.Equals("sphot"))
        {
            string soluong = Request.QueryString["soluong"];
            Response.Write(new SanPhamDAO().sanPHam_GetTopHot_Json(soluong));
        }
        //lay cac san pham ban chay
        if (type.Equals("spbanchay"))
        {
            string soluong = Request.QueryString["soluong"];
            Response.Write(new SanPhamDAO().sanPHam_GetTopBanChay_Json(soluong));
        }
        //Lay cac san pham giam gia
        if (type.Equals("giamgia"))
        {
            string soluong = Request.QueryString["soluong"];
            Response.Write(new SanPhamDAO().sanPHam_GetTopCoGiamGia_Json(soluong));
        }
        //lay danh muc nhom san pham
        if(type.Equals("menu"))
        {
            Response.Write(new QuanTriDAO().sanpham_nhom_getall_Json());
        }
        //Lay danh muc noi san xuat san pham
        if (type.Equals("noisx"))
        {
            Response.Write(new SanPham_NoiSXDAO().sanPham_NoiSX_GetAll_Json());
        }
        //Lay danh muc loai san pham
        if (type.Equals("loai"))
        {
            Response.Write(new SanPham_LoaiDAO().sanPham_Loai_GetAll_Json());
        }
        //Lay cac san pham trong gio hang
        if (type.Equals("giohang"))
        {
            Response.Write(new SanPham_LoaiDAO().sanPham_Loai_GetAll_Json());
        }
        //Lay thong tin chi tiet 1 san pham
        if(type.Equals("getbyid"))
        {
            Response.Write(new SanPhamDAO().sanPhamInfo_getById_json(_id));
        }
    }
}
